package com.yupi.yuojbackendjudgeservice.judge;


import com.yupi.yuojbackendjudgeservice.judge.strategy.DefaultJudgeStrategy;
import com.yupi.yuojbackendjudgeservice.judge.strategy.JavaLanguageJudgeStrategy;
import com.yupi.yuojbackendjudgeservice.judge.strategy.JudgeContext;
import com.yupi.yuojbackendjudgeservice.judge.strategy.JudgeStrategy;
import com.yupi.yuojbackendmodel.model.codesandbox.JudgeInfo;
import com.yupi.yuojbackendmodel.model.entity.QuestionSubmit;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;

/**
 * 判题管理（简化调用）
 */
@Service
public class JudgeManager {

    /**
     * 执行判题
     *
     * @param judgeContext
     * @return
     */
    JudgeInfo doJudge(@NotNull JudgeContext judgeContext) {
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        //如果
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        //策略模式 如果传过来的语言是java语言则采用java的判题逻辑
        if ("java".equals(language)) {
            judgeStrategy = new JavaLanguageJudgeStrategy();
        }
        //可以进行其他的拓展 如果是其他语言或者其他策略都可以在这里进行拓展  new的是一个实现类 需要执行实现类里面的重写的接口的方法
        return judgeStrategy.doJudge(judgeContext);
    }

}
